package model.tsp;

import util.DistanceUtil;

import java.util.List;

public class Problem {

    private List<Integer> x;
    private List<Integer> y;
    private int[][] distance;
    private String edgeWeightType;

    public Problem(List<Integer> x, List<Integer> y, String edgeWeightType) {
        this.x = x;
        this.y = y;
        this.edgeWeightType = edgeWeightType;
        buildDistMatrix();
    }

    private void buildDistMatrix() {
        int len = x.size();
        distance = new int[len][len];
        for (int i = 0; i < len; i++) {
            distance[i][i] = 0;
            for (int j = i + 1; j < len; j++) {
                if (edgeWeightType.equals("EUC_2D")) {
                    distance[i][j] = DistanceUtil.calculateEuc2D(x.get(i), y.get(i), x.get(j), y.get(j));
                } else if (edgeWeightType.equals("ATT")) {
                    distance[i][j] = DistanceUtil.calculateATT(x.get(i), y.get(i), x.get(j), y.get(j));
                } else {
                    throw new RuntimeException("未能识别边权重计算类型");
                }
                distance[j][i] = distance[i][j];
            }
        }
    }

    public int[][] getDistance() {
        return distance;
    }

    public List<Integer> getX() {
        return x;
    }

    public List<Integer> getY() {
        return y;
    }

    public int getNodeNum() {
        return x.size();
    }
}
